import pandas as pd
import akshare as ak
import os

# akshare https://www.akshare.xyz/  pip install akshare

# 获取行情数据
def get_ticker_data(symbol, start_date, end_date):
    df = ak.stock_zh_a_daily(symbol, start_date, end_date, adjust="qfq")
    print(df)
    df.index = pd.to_datetime(df.date)
    df = df[['open', 'high', 'low', 'close', 'volume']]
    return df

def get_data():
    # symbol =input("请输入股票代码: \n")
    # start_date = input("请输入开始时间: \n")
    # end_date = input("请输入结束时间: \n")
    symbol = "sz000002"
    start_date = "20170301"
    end_date = '20210907'
    df = get_ticker_data(symbol, start_date, end_date)
    print(df.info())
    print(df.describe())

    df.to_csv(symbol + ".csv")

get_data()